<template>
	<view class="mainpadding" v-if="pageShow" style="padding-bottom: 150rpx;">
		<!-- <u-popup :show="show" @close="close" :round="7">
			<view class="" style="padding: 30rpx 0;">
				<view class="titletext fonweight zhonghei textcenter">选择配送时间</view>
				<view class="flexleft">
					<scroll-view scroll-y="true" style="height: 500rpx;width: 271rpx;">
						<view class="" style="background-color: #F5F5F5;">
							<view class="yixbtn">今天（周日）</view>
							<view class="wxbtn" v-for="item in 30">今天（周日）</view>
						</view>
					</scroll-view>
					<scroll-view scroll-y="true" style="height: 500rpx; ">
						<view class="">
							<view class="xiahuaxian margin_top flexcenter">
								<view class="ershil xiaocheng">15:00-16:00</view>
							</view>
							<view class="xiahuaxian margin_top flexcenter">
								<view class="ershil xiaohei">15:00-16:00</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="mainpadding">
					<view class="bigbtn margin_top">选择并使用</view>
				</view>
			</view>
		</u-popup> -->
		<!-- 地址 -->
		<view class="ffffff radius mainpadding flexbetween" @click="tzshdz">
			<view class="" v-if="addressData">
				<view class="flexleft">
					<view class="titletext zhonghei fonweight margin_right4">{{addressData.name}}</view>
					<view class="titletext zhonghei fonweight">{{addressData.mobile}}</view>
				</view>
				<view class="ershil margin_top xiaohui">{{addressData.cityinfo}}{{addressData.addressData}}</view>
			</view>
			<view class="titletext zhonghei fonweight" v-if="!addressData">点击选择收货地址</view>
			<u-icon name="arrow-right" color="#999"></u-icon>
		</view>
		<!-- 选择配送时间 -->
		<view class="ffffff mainpadding radius margin_top flexbetween" @click="messageTime.timeShow = true">
			<view class="ershiba zhonghei">选择配送时间</view>
			<view class="flexright">
				<input type="text" class="textright" disabled="" placeholder="请选择" v-model="time" />
				<u-icon name="arrow-right" color="#999"></u-icon>
			</view>
		</view>
		<!-- 商品 -->
		<view class="ffffff mainpadding radius margin_top flexbetween" v-for="item in goodsdata">
			<image style="width:109.5rpx;height:109.5rpx;" :src="item.goodsinfo.image_text" mode="">
			</image>
			<view class="" style="width: 80%;">
				<view class="titletext zhonghei">{{item.goodsinfo.name}}</view>
				<view class="xiaohui margin_top1 smalltext">{{item.sku2.difference}}</view>
				<view class="flexbetween margin_top1">
					<view class="titletext xiaocheng fonweight">￥{{item.total_goods_price}}</view>
					<view class="flexright">
						<view class="ershil xiaocheng fonweight">x{{item.number}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="ffffff mainpadding radius margin_top">
			<view class="xiahuaxian flexbetween">
				<view class="ershiba zhonghei fonweight">配送费</view>
				<view class="ershiba xiaohui">￥5.00</view>
			</view>
			<view class="margin_top flexbetween">
				<view class="ershiba zhonghei fonweight">打包费</view>
				<view class="ershiba xiaohui">￥5.00</view>
			</view>
		</view> -->
		<view class="gudingdb ffffff mainpadding flexbetween">
			<view class="xiaocheng strongtext">￥
				<text class="bigtext fonweight xiaocheng">{{dataAll.payinfo.pay_price}}</text>
			</view>
			<view class="huabtn flexcenter" @click="tzzf">立即预定</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				value: "",
				lastmsg: null,
				addressid: "",
				pageShow: false,
				goodsdata: null,
				addressData: null,
				dataAll: null,
				messageTime: {
					timeShow: false,
					title: "选择配送时间",
					mode: "datetime", //date日期，datetime年月日时分秒，time时间，year-month年月
					minDate: Number(new Date()) //最小时间
				},
				time: ""

			}
		},
		onLoad(options) {
			this.lastmsg = JSON.parse(decodeURIComponent(options.msg));
		},
		onShow() {
			uni.$off('checkAddressId')
			uni.$on('checkAddressId', data => {
				this.addressid = data
			})
			this.getdingdan()
		},
		methods: {
			timeConfirm(e) {
				this.time = e
			},
			getdingdan() {
				let data = this.lastmsg
				this.$set(data, "address_id", this.addressid)
				httpRequest.request("/api/Foodshoporder/getOrderSure", 'POST', data, false, false, true).then(res => {
					if (res.code == 1) {
						this.goodsdata = res.data.goodsdata
						this.addressData = res.data.address
						if (res.data.address) {
							this.addressid = res.data.address.id
						}
						this.dataAll = res.data
						this.pageShow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			close() {
				this.show = false
			},
			// 跳转支付
			tzzf() {
				let data = this.lastmsg
				if (this.addressid == "") {
					httpRequest.toast("请选择收货地址")
					return false
				}
				if (this.time == "") {
					httpRequest.toast("请选择配送时间")
					return false
				}
				this.delitem()
				this.$set(data, "address_id", this.addressid)
				this.$set(data, "pstime", this.time)
				httpRequest.request("/api/Foodshoporder/addOrder", 'POST', data, false, false, true).then(res => {
					if (res.code == 1) {
						let data = {
							order_id: res.data.order_id,
							pay_price: res.data.pay_price.pay_price,
							pay_score: res.data.pay_price.score,
							type: 4
						}
						uni.redirectTo({
							url: '/pages_index/zhifuTwo?msg=' + encodeURIComponent(JSON.stringify(data))
						})
					}
				})
			},
			delitem() {
				let data = []
				this.lastmsg.lists.forEach(item => {
					data.push({
						goods_id: item.goods_id,
						sku_id: item.sku_id,
						shop_id: this.lastmsg.shop_id,
						foodshop_id: this.lastmsg.foodshop_id
					})
				})
				httpRequest.request('/api/foodshopgoodscartcl/delCart', 'POST', {
					data
				}, false, false, true).then(res => {})
			},
			tzshdz() {
				uni.navigateTo({
					url: '/pages_mypage/shouhuodizhi?type=1'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wxbtn {
		font-weight: 500;
		font-size: 26rpx;
		color: #333333;
		// background-color: #FFFFFF;
		padding: 30rpx 15rpx 30rpx 30rpx;
	}

	.left_box {
		position: fixed;
		left: 0;
		bottom: 0;
		// width: 23%;
		height: calc(100vh - 781rpx);
		overflow-y: auto;
		background: #F5F5F5;
		box-sizing: border-box;
	}

	.yixbtn {
		font-weight: 500;
		font-size: 26rpx;
		color: #FF8505;
		background-color: #FFFFFF;
		padding: 30rpx 15rpx 30rpx 30rpx;
	}

	.huabtn {
		width: 295rpx;
		height: 80rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		background-color: #FF9341;
	}
</style>